package com.cwj.thread;

import java.util.concurrent.TimeUnit;

/**
 * @author chenwujie
 * @date 2021-01-11 13:22
 */
public class JoinTest {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new MyThread1();
        Thread t2 = new MyThread2();
        Thread t3 = new MyThread3();

        System.out.printf("%23s\n" , System.currentTimeMillis());

//        System.out.println("start 1");
        t1.start();

//        System.out.println("start 2");
        t2.start();

//        System.out.println("start 3");
        t3.start();

//        Thread.sleep(0_000L);
        System.out.printf("%s%20s\n" , "1->", System.currentTimeMillis());
//        t1.join();
//
//        System.out.printf("%s%20s\n" , "2->", System.currentTimeMillis());
//        t2.join();
//
//        System.out.printf("%s%20s\n" , "3->", System.currentTimeMillis());
//        t3.join();
        System.out.println("end!");

        TimeUnit.MILLISECONDS.sleep(20000);
        System.out.println(System.currentTimeMillis());
        t1.join();
        System.out.println(System.currentTimeMillis());
    }

    public static class MyThread1 extends Thread{

        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName());
            try {
                Thread.sleep(4000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(" MyThread1 " + System.currentTimeMillis());
        }
    }
    public static class MyThread2 extends Thread{

        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName());
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(" MyThread2 " + System.currentTimeMillis());
        }
    }
    public static class MyThread3 extends Thread{

        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName());
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(" MyThread3 " + System.currentTimeMillis());
        }
    }
}
